//拼团报名列表
exports.bulk_purchase_open_user = function (req, res) {

    //获取restful参数 
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    //几人可以成团
    var minCount = 0;

    //任务流创建
    async.waterfall([

        //1.拼团活动
        function (cb) {
            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.search_bulk_purchase_activity_info + "/oa_id/" + restfulParams.bpau_oaid,
                    method: 'GET',
                },
                function (err, data) {
                    //判断是否有错误信息
                    if (err) {
                        return cb(err, data);
                    }

                    minCount = data.data[0].bpac_min_count;

                    cb();
                }
            );

        },


            //1.拼团报名列表
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.bulk_purchase_join_user + "/bpau_oaid/" + restfulParams.bpau_oaid + "/bpau_is_complete/0/bpau_fid/0/count/1/skip/0/limit/10/o_pay_status/1",
                        method: 'POST',
                        data: {
                            fields: ["bpau_id","u_header_url","u_nickname","bpau_user_count","bpau_join_time","bpau_member_count"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        //console.log(data.data)

                        

                        resultData.joinCount    = data.count;
                        resultData.joinUserData = data.data;

                        cb();
                    }
                );

            },

            //查询还差成团的人数
            function(cb){

                for(var i =0;i<resultData.joinUserData.length;i++){

                    var bpau_user_count = resultData.joinUserData[i].bpau_user_count;

                    var differCount  = resultData.joinUserData[i].bpau_member_count - bpau_user_count;

                    resultData.joinUserData[i].differCount = differCount;

                }

                cb();
                
            }


        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}